package angels.client.Tasks;

import java.net.HttpURLConnection;
import java.util.TimerTask;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

import com.google.android.maps.GeoPoint;

import angels.client.Listeners.BlockingLocationListener;
import angels.client.Listeners.UserListener;
import angels.client.Services.UserService;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;

public class SetSharingTask extends TimerTask {    
    private final DefaultHttpClient client;
    private final UserService service;
    private final UserListener listener;
    private final String username;
    private final String desc;
    private final GeoPoint selGP;
    private final String category,subcategory;
    
    //Constructor
    public SetSharingTask(UserService service, String username,String desc,GeoPoint selGP, String category, String subcategory, UserListener listener) {
        this.service = service;
        this.listener=listener;
        this.username=username;
        this.desc=desc;
        this.category=category;
        this.subcategory=subcategory;
        this.selGP=selGP;
        // set parameters
        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
        client = new DefaultHttpClient(httpParameters);
    }
    
    @Override
    public void run() {
        try {
        	String path= service.setSharingURL(username,desc, selGP,category,subcategory);
            HttpGet request = new HttpGet(path);
            HttpResponse response = client.execute(request);
            
            if (response.getStatusLine().getStatusCode() != HttpURLConnection.HTTP_OK)
                return;

            // notify service 
            //listener.notifyBroadcast();
            
        } catch (Exception e) {}
    }
}